package com.centaline.androidsalesblog.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;

/**
 * {@link android.support.design.widget.TabLayout}配套使用的
 * {@link FragmentPagerAdapter}
 * Created by guilin on 16/3/4.
 */
public class TabFragmentAdapter extends FragmentPagerAdapter {

    private final ArrayList<Fragment> fragmentArrayList;
    private final ArrayList<String> titleArrayList;

    public TabFragmentAdapter(FragmentManager fm, ArrayList<Fragment> fragmentArrayList, ArrayList<String> titleArrayList) {
        super(fm);
        this.fragmentArrayList = fragmentArrayList;
        this.titleArrayList = titleArrayList;
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentArrayList.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleArrayList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentArrayList.size();
    }
}
